﻿using System.Globalization;

namespace ODM.Data.Model
{
    public class Variable
    {
        public Variable()
        {

        }

        public Variable(Variable source)
        {
            this.ID = source.ID;
            this.Code = source.Code;
            this.Name = source.Name;
            this.Unit = new Unit(source.Unit);
            this.Speciation = source.Speciation;
            this.GeneralCategory = source.GeneralCategory;
            this.DataType = source.DataType;
            this.ValueType = source.ValueType;
            this.SampleMedium = source.SampleMedium;
            this.IsRegular = source.IsRegular;
            this.NoDataValue = source.NoDataValue;
            this.TimeSupport = new UnitValue<double>(source.TimeSupport);
        }

        public int ID { get; set; }

        public string Code { get; set; }

        public string Name { get; set; }

        public Unit Unit { get; set; }

        public string Speciation { get; set; }

        public string GeneralCategory { get; set; }

        public string DataType { get; set; }

        public string ValueType { get; set; }

        public string SampleMedium { get; set; }

        public bool IsRegular { get; set; }

        public double NoDataValue { get; set; }

        public UnitValue<double> TimeSupport { get; set; }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "{0} - {1}", this.Code, this.Name);
        }

        public static bool operator ==(Variable q1, Variable q2)
        {
            if (ReferenceEquals(q1, q2))
                return true;
            if (ReferenceEquals(q1, null) || ReferenceEquals(q2, null))
                return false;
            else
                return q1.GetHashCode() == q2.GetHashCode();
        }

        public static bool operator !=(Variable q1, Variable q2)
        {
            return !(q1 == q2);
        }

        public override bool Equals(object obj)
        {
            Variable v = obj as Variable;
            if (v == null)
                return false;

            return this == v;
        }

        public override int GetHashCode()
        {
            return string.Format(CultureInfo.InvariantCulture, "Variable:{0}{1}{2}", this.ID, this.Code, this.Name, this.Speciation, this.GeneralCategory, this.DataType, this.ValueType, this.SampleMedium, this.IsRegular, this.NoDataValue).GetHashCode();
        }
    }
}
